//*****************************************************************************************
// Copyright (c) 2005 Sony DADC
// All rights reserved.
//
// $FileName    : securom_api.h
// $ProjectName : SDK
// $Created     : 02.03.2005  12:14
//
// Content:
//
//*****************************************************************************************

#ifndef SECUROM_SDK_H
#define SECUROM_SDK_H

#include <windows.h>
#include <stdio.h>

#if 0
static BOOL SecuROM_Tripwire() 
{ 
	char	event_name[50];
		
	sprintf(event_name, "v7_%04d", (GetCurrentProcessId() ^ 0x19EA3FD3) );
	
	if(HANDLE S7hnd = OpenEventA(EVENT_MODIFY_STATE, FALSE, event_name))
	{
		CloseHandle(S7hnd);
		return TRUE;
	}

	return FALSE;
}
#endif // 0

#define SECUROM_MARKER_PERFORMANCE_ON(id) { { __asm _emit 0xEB __asm _emit 0x0E __asm _emit 'M' __asm _emit 'a' __asm _emit '0' __asm _emit 'W' __asm _emit 'y' __asm _emit 'G' __asm _emit '1' __asm _emit 'k' __asm _emit 'm' __asm _emit 0x01 __asm _emit (id & 0xFF) __asm _emit ((id >> 8) & 0xFF) __asm _emit ((id >> 16) & 0xFF) __asm _emit ((id >> 24) & 0xFF) }
#define SECUROM_MARKER_PERFORMANCE_OFF(id) { __asm _emit 0xEB __asm _emit 0x0E __asm _emit 'M' __asm _emit 'a' __asm _emit '0' __asm _emit 'W' __asm _emit 'y' __asm _emit 'G' __asm _emit '1' __asm _emit 'k' __asm _emit 'm' __asm _emit 0x02 __asm _emit (id & 0xFF) __asm _emit ((id >> 8) & 0xFF) __asm _emit ((id >> 16) & 0xFF) __asm _emit ((id >> 24) & 0xFF) } }

#define SECUROM_MARKER_SECURITY_ON(id) { { __asm _emit 0xEB __asm _emit 0x0E __asm _emit 'M' __asm _emit 'a' __asm _emit '0' __asm _emit 'W' __asm _emit 'y' __asm _emit 'G' __asm _emit '1' __asm _emit 'k' __asm _emit 'm' __asm _emit 0x11  __asm _emit (id & 0xFF) __asm _emit ((id >> 8) & 0xFF) __asm _emit ((id >> 16) & 0xFF) __asm _emit ((id >> 24) & 0xFF) }
#define SECUROM_MARKER_SECURITY_OFF(id) { __asm _emit 0xEB __asm _emit 0x0E __asm __asm _emit 'M' __asm _emit 'a' __asm _emit '0' __asm _emit 'W' __asm _emit 'y' __asm _emit 'G' __asm _emit '1' __asm _emit 'k' __asm _emit 'm' __asm _emit 0x12 __asm _emit (id & 0xFF) __asm _emit ((id >> 8) & 0xFF) __asm _emit ((id >> 16) & 0xFF) __asm _emit ((id >> 24) & 0xFF) } }

#define SECUROM_MARKER_HIGH_SECURITY_ON(id) { { __asm _emit 0xEB __asm _emit 0x0E __asm _emit 'M' __asm _emit 'a' __asm _emit '0' __asm _emit 'W' __asm _emit 'y' __asm _emit 'G' __asm _emit '1' __asm _emit 'k' __asm _emit 'm' __asm _emit 0x21  __asm _emit (id & 0xFF) __asm _emit ((id >> 8) & 0xFF) __asm _emit ((id >> 16) & 0xFF) __asm _emit ((id >> 24) & 0xFF) }
#define SECUROM_MARKER_HIGH_SECURITY_OFF(id) { __asm _emit 0xEB __asm _emit 0x0E __asm _emit 'M' __asm _emit 'a' __asm _emit '0' __asm _emit 'W' __asm _emit 'y' __asm _emit 'G' __asm _emit '1' __asm _emit 'k' __asm _emit 'm' __asm _emit 0x22 __asm _emit (id & 0xFF) __asm _emit ((id >> 8) & 0xFF) __asm _emit ((id >> 16) & 0xFF) __asm _emit ((id >> 24) & 0xFF) } }


#define SECUROM_MARKER_VM_CALL(id, code, data) { __asm _emit 0xEB __asm _emit 0x18  \
			__asm _emit 'M' __asm _emit 'a' __asm _emit '0' __asm _emit 'W' __asm _emit 'y' __asm _emit 'G' __asm _emit '1' __asm _emit 'k' __asm _emit 'm' \
			__asm _emit 0x31   \
			__asm _emit (id & 0xFF) __asm _emit ((id >> 8) & 0xFF) __asm _emit ((id >> 16) & 0xFF) __asm _emit ((id >> 24) & 0xFF)  \
			__asm push offset code \
			__asm push offset data }


static unsigned char MACRO_ADD[] =
{
	0xEC,0xAF,0xCA,0x36,0xB7,0x0D,0x59,0xC1,0xFA,0xA7,0x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,0xE2,0x07,0x1F,0x47,0xB7,0x1B,0xAF,0x88,0x21,0xDE,0x8C,0x98,0x52,0xA8,0x70,0x32,
	0x92,0x80,0x1B,0x00,0xFD,0x49,0x32,0xF0,0x1E,0xB8,0xDB,0x65,0x33,0x93,0x93,0x8E,0xA0,0x97,0xEF,0xA7,
	0xE3,0xD2,0x84,0x49,0x2C,0xE0,0xD9,0xC0,0x59,0xF8,0xCD,0x62,0x83,0xEF,0x7B,0x55,0x5D,0x6B,0x7F
};

#pragma pack(push, 1)
typedef struct
{
	void  *code_ptr;
	
	union
	{
		struct
		{
			DWORD Param1;
			DWORD Param2;
			DWORD Param3;
			DWORD Param4;
			DWORD Param5;
			DWORD Param6;
		}std;
		struct
		{
			DWORD dest;
			DWORD src;
			DWORD Param3;
			DWORD Param4;
			DWORD Param5;
			DWORD Param6;
		}arithmetic;
		struct
		{	
			DWORD compare_me;
			DWORD with_value;
			DWORD if_equal;
			DWORD if_not_equal;
			DWORD Param5;
			DWORD Param6;
		}cmp;
	};	
	
	
} VirtualMachine_t;
#pragma pack(pop)

#define SET_LABEL_ADDR(param, label_addr) \
	{ \
		DWORD addr; \
		__asm { mov addr, offset label_addr } \
		param = addr; \
	}


#endif





